package com.zxj.schoolxianyu.controller;

import com.zxj.schoolxianyu.entity.comments;
import com.zxj.schoolxianyu.entity.goods;
import com.zxj.schoolxianyu.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
public class goodsController {

    @Autowired
    private addGoodsService addGoodsService;
    @Autowired
    private getGoodsService getGoodsService;
    @Autowired
    private getTypeGoodsService getTypeGoodsService;
    @Autowired
    private addCommentService addCommentService;
    @Autowired
    private getcommentsService getCommentsService;
    @Autowired
    private searchGoodsService searchGoodsService;
    @Autowired
    private buyService buyService;


    @PostMapping("/add")
    public String add(@RequestBody goods g) {
        return addGoodsService.addGoods(g);
    }

    @GetMapping("/getgoods")
    public String getgoods() {
        return getGoodsService.getGoods();
    }

    @GetMapping("/gettypegoods")
    public String gettypegoods(@RequestParam int classificationid) {
        return getTypeGoodsService.getTypeGoods(classificationid);
    }

    @PostMapping("/addcomment")
    public String addcomment(@RequestBody comments c) {
        return addCommentService.addComment(c);
    }

    @GetMapping("/getcomments")
    public String getcomments(@RequestParam int goodsid) {
        return getCommentsService.getcomments(goodsid);
    }

    @GetMapping("/searchgoods")
    public String searchgoods(@RequestParam String target) {
        return searchGoodsService.searchGoods(target);
    }

    @PostMapping("/buygoods")
    public String buygoods(@RequestParam int goodsid, @RequestParam String username, @RequestParam int price) {
        return buyService.buy(goodsid, username, price);
    }

}
